<?php
namespace App\Libs\Passport;
use \App\Libs\Helper\PasswordHelper;
class Register extends \App\Libs\Base\Singleton
{
    private $userTable = 't_hera_user';
    public function regist($info) {
        if (empty($info['mobile']) && empty($info['email'])) {
            return FALSE;
        }
        // 加密密码
        list($salt, $password) = PasswordHelper::encrypt($info['password']);
        $info['password'] = $password;
        $info['salt'] = $salt;
        $info['ctime'] = date('Y-m-d H:i:s');
        // 写入数据表
        $uid = \App\Libs\DB\HeraPdo::instance()->insert($this->userTable, $info);
        // 发送验证码
        if ($uid) {
            if ( ! empty($info['email'])) {
                $engine = new \App\Libs\Views\Smarty();
                $content = $engine->fetch(array('params' => array(
                    'username' => $info['nickname'],
                    'company' => COMPANY,
                    'activeUrl' => BASE_URL . '/passport/active?code=' . urlencode(Activation::generate($uid, $info['email'])),
                ), 'tpl' => 'mail/active.tpl.html'));
                \App\Libs\Helper\MailHelper::send($info['email'], COMPANY . '激活邮件', $content);
            }
            return TRUE;
        }

        return FALSE;
    }
}
